package com.yanqu.road.server.cmd.activity.peakseacraft.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakSeacraftProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.peakseacraft.PeakSeacraftModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Description
 */
@Cmd(code = GameProtocol.S_PEAK_SEACRAFT_RECEIVE_WIN_STREAK_REWARD_FROM_CROSS, desc = "海上争霸 南海丝路 领取连胜奖励 跨服返回区服 协议")
public class PeakSeacraftReceiveWinStreakRewardFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakSeacraftProto.PeakSeacraftReceiveWinStreakRewardRespMsg reqMsg = PeakSeacraftProto.PeakSeacraftReceiveWinStreakRewardRespMsg.parseFrom(packet.getBytes());
        if(reqMsg.getRet() == 0){
            ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(reqMsg.getActivityId());
            if (null == activityInfo){
                ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
                return;
            }
            if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
                // 加奖励
                player.getModule(CurrencyModule.class).addCurrency(reqMsg.getReward(), eLogMoneyType.PeakSeacraftActivity, eLogMoneyType.PeakSeacraftActivityWinStreakReward);
                // 对决奖励
                player.getModule(PeakSeacraftModule.class).battleEnd(reqMsg.getResult());
            }
        }
        player.sendPacket(ClientProtocol.U_PEAK_SEACRAFT_RECEIVE_WIN_STREAK_REWARD, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
